var crypto = require('crypto'),//加密组件
    User = require('../models/user.js'),
    Hotel = require('../models/hotel.js'),
    Countries = require('../models/countries.js');

module.exports= function(app) {

    app.get("/getten",function(req,res){
        //var page = req.query.p? req.query.p :1;
        Countries.getTen(null,null,function(err,countries){
            if(err){
                countries = [];
            }
            res.render("index",{
                title:"主页",
                user: req.session.user,
                countries: countries
            });
        });
    });

    app.get("/insert",function(req,res,next){
        var _countries = {
            country: "test",
            flag: "tt",
            country_code: "ts"
        };
        var obj =new Countries(_countries);
        obj.save(function(err,countries){
            if(err){
                countries = [];
                msg="插入失败";
            }
            res.render("index",{
                title:"插入成功",
                user: req.session.user,
                countries: countries
            });
        });
    });

    app.get("/update",function(req,res,next){
        var _countries = {
            id : 243,
            country: "test6",
            flag: "tt6",
            country_code: "ts6"
        };
        var obj =new Countries(_countries);
        obj.update(function(err,countries){
            if(err){
                countries = [];
                msg="更新失败";
            }
            res.render("index",{
                title:"更新成功",
                user: req.session.user,
                countries: countries
            });
        });
    });

    app.get("/delete",function(req,res,next){
        var _countries = {
            id : 244
        };
        var obj =new Countries(_countries);
        obj.delete(function(err,countries){
            if(err){
                countries = [];
                msg="删除失败";
            }
            res.render("index",{
                title:"删除成功",
                user: req.session.user,
                countries: countries
            });
        });
    });

    app.get("/getone",function(req,res,next){
        var _countries = {
            id : 242
        };
        var obj =new Countries(_countries);
        obj.getOne(function(err,countries){
            if(err){
                countries = [];
                msg="查询失败";
            }
            res.render("index",{
                title:"查询成功",
                user: req.session.user,
                countries: countries
            });
        });
    });

}